# Don't Delete this file,Please!

import json
import os

def inputurl():
    urllist=[]
    print("每行输入一个url，以0结束")
    url=input()
    while not url=="0":
        urllist.append(url)
        url=input()
    return urllist

os.system("git pull origin master")

while True:
    print(u"年级:",end=" ")
    grade=input()
    print(f"get=-{grade}-")
    print(u"学科:",end=" ")
    subject=input()
    try:
        filedt=open("./"+str(grade)+"/"+str(subject)+".json","r",encoding='utf-8')
        #file=file.read(encode="utf-8")
        filejs=json.load(filedt)
        filedt.close()
    except IOError:
        filejs={"SUBJECT":subject,"ASSETS":[]}
    print(filejs)
    print("Date:",end=" ")
    date=input()
    flag=0
    for ae in filejs["ASSETS"]:
        if ae["date"]==date:
            flag=1
            print("今日该科目课件已添加，url如下")
            print(ae["url"])
            print("取消 or 追加？(Y/N) :",end=" ")
            opt=input()
            if opt=="N" :
                urllist=inputurl()
                ae["url"]+=urllist
                print(filejs)
            else :
                exit(0)
    if flag==0:
        urllist=inputurl()
        node={"date":date,"url":urllist}
        filejs["ASSETS"].append(node)
        print(filejs)
    fileout=json.dumps(filejs,sort_keys=True,indent=4,ensure_ascii=False)
    filedt=open(grade+"/"+subject+".json","w",encoding='utf-8')
    filedt.write(fileout)
    filedt.close()
    print("Will you keep update?Y/N")
    going=input()
    if going == "N":
        break




os.system("git add *")
os.system("git commit -m \"by zjb's python\"")
os.system("git push origin master")
os.system("git push second master")